<?php

if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval(getvar("gametype"));
$chk = new CheckMode_3d($curruser['acl'], 5, $gametype);
$chk->checkShow3dPage();
unset($chk);
$tblName = $g_gametype_3d[$gametype]['ch'];
$tbl = $g_gametype_3d[$gametype]['en'];
$ui = new UI_3D(true);
$tpl = new Template2();
$conf = new Config();
$betnameArr = $_sb_Arr;
$autorateArr = $g_autorate_sb;
include_once( "class_sb/AutoRateConfig_sb.php" );
$AutoRateConfig_sb = new AutoRateConfig_sb($betnameArr, $autorateArr, $gametype);
if (ispost())
{
    $longautoadown = intval(getvar("longautoadown_{$tbl}"));
    $conf->set("longautoadown_{$tbl}", $longautoadown);
    $fields_data = array ();
    foreach ($betnameArr as $keyStr => $val)
    {
        if (in_array($keyStr, $autorateArr))
        {
            $money = "money" . $keyStr;
            $downrate = "downrate" . $keyStr;
            $uprate = "uprate" . $keyStr;
            $limitrate = "limitrate" . $keyStr;
            $typeflag = "typeflag" . $keyStr;
            $uprateData = "";
            $amount_255 = "amount_255" . $keyStr;
            if (!isset($_POST[$amount_255]))
            {
                continue;
            }
            if (isset($_POST[$uprate]))
            {
                $uprateData = round(floatval(trim($_POST[$uprate])), 3);
            }
            else
            {
                $uprateData = 0;
            }
            $amount_255_val = intval(trim($_POST[$amount_255]));
            if ($amount_255_val < 0)
            {
                $amount_255_val = 0;
            }
            $moneyTemp = intval(trim($_POST[$money]));
            $typeflagTemp = intval(trim($_POST[$typeflag]));
            $fields_data[] = array ("id" => $keyStr, "subid" => 0, "money" => $moneyTemp < 0 ? "0" : $moneyTemp, "downrate" => round(floatval(trim($_POST[$downrate])), 3) < 0 ? "0" : round(floatval(trim($_POST[$downrate])), 3), "uprate" => $uprateData < 0 ? "0" : $uprateData, "limitrate" => round(floatval(trim($_POST[$limitrate])), 3) < 0 ? "0" : round(floatval(trim($_POST[$limitrate])), 3), "typeflag" => $typeflagTemp, "amount_255" => $amount_255_val < 0 ? "0" : $amount_255_val);
            if ($moneyTemp == 0)
            {
                getdb("update autorate_config_ss set money = 0, updatetime = '" . date("Y-m-d H:i:s") . "' where bettype = {$keyStr} and  subid = 0 and typeflag = {$typeflagTemp} and money != 0");
            }
        }
    }
    if (0 < count($fields_data))
    {
        $AutoRateConfig_sb->updateAutoRate($fields_data);
    }
    unset($fields_data);
}
$theadContent = "<tr class=\"bgClc_" . $gametype . "\"><td>玩法</td><td>金额</td><td>降赔率</td><td>升赔率</td><td>最低赔率</td><td>实货限额</td></tr>";
$longautoadownVal = intval($conf->get("longautoadown_{$tbl}"));
$autorateData = $AutoRateConfig_sb->getAutoRateAll();
$tempStr = "";
$tempI = 0;
$tempClass = 2;
$showHeadArr =array();
if ($autorateData == false)
{
    $tempStr = "<tr class=\"td2\"><td colspan=6 align=ccenter>查无相关资料</td></tr>";
}
else
{
    foreach ($betnameArr as $keyStr => $valName)
    {
        if (isset($showHeadArr[$keyStr]))
        {
            $tempStr .= $theadContent;
        }
        if (isset($autorateData[$keyStr]))
        {
            $val = $autorateData[$keyStr];
            ++$tempI;
            $tempClass = $tempClass % 2 + 1;
            $tempStr .= "<tr class=\"td2 row{$tempClass}\">";
            $tempStr .= "<td class=\"td17\" align=left>{$valName}<input type=\"hidden\" value=\"" . $val['typeflag'] . "\" name=\"typeflag" . $keyStr . "\"  /></td>";
            $tempStr .= "<td><input type=\"text\" name=\"money" . $keyStr . "\" value=\"" . ( $val['money'] < 0 ? "0" : $val['money'] ) . "\" size=\"8\" /></td>";
            $tempStr .= "<td><input type=\"text\" name=\"downrate" . $keyStr . "\" value=\"" . ( $val['downrate'] < 0 ? "0" : $val['downrate'] ) . "\" size=\"5\" /></td>";
            $tempStr .= "<td>";
            if ($val['typeflag'] == 1)
            {
                $tempStr .= "<input type=\"text\" name=\"uprate" . $keyStr . "\" value=\"" . ( $val['uprate'] < 0 ? "0" : $val['uprate'] ) . "\" size=\"5\" />";
            }
            else
            {
                $tempStr .= "&nbsp;";
            }
            $tempStr .= "</td>";
            $tempStr .= "<td><input type=\"text\" name=\"limitrate" . $keyStr . "\" value=\"" . ( $val['limitrate'] < 0 ? "0" : $val['limitrate'] ) . "\" size=\"5\" /></td>";
            $tempStr .= "<td><input type=\"text\" name=\"amount_255" . $keyStr . "\" value=\"" . ( $val['amount_255'] < 0 ? "0" : $val['amount_255'] ) . "\" size=\"5\" /></td>";
            $tempStr .= "</tr>";
        }
        else
        {
            $tempStr .= "<tr class=\"td2 row{$tempClass}\"><th>{$valName}</th><td colspan=5 align=ccenter>查无此玩法的相关资料，请洽系统管理者</td></tr>";
        }
    }
    unset($autorateData);
}
$tpl->load("main", "autorate_3d.htm");
$tpl->set(array ("action" => "op.php?op=admin&fp=autorate_sb&gametype={$gametype}", "reload" => "op.php?op=admin&fp=autorate_sb&gametype={$gametype}", "tbodycontente" => $tempStr, "tblName" => $tblName, "theadContent" => $theadContent, "gametype" => $gametype));
$ui->set("csslink", "<link REL=\"StyleSheet\" type=\"text/css\" href=\"core/tpl/k2/rate3d.css\">");
$ui->header();
include( "admin_menu_3d.php" );
$tpl->show("main");
echo "</td></tr></table>";
$ui->footer();